package cn.com.ddapp.ddm.ui.order;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.ActivityManager;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.Entity;
import cn.com.ddapp.ddm.bean.order.GoodsEval;
import cn.com.ddapp.ddm.bean.order.GoodsEvalEntity;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.dialog.CommonDialog;
import cn.com.ddapp.ddm.ui.dialog.DialogHelper;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.util.FileUtil;
import cn.com.ddapp.ddm.util.ImageUtils;
import cn.com.ddapp.ddm.util.MethodsCompat;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.StringUtils;
import cn.com.ddapp.ddm.util.TLog;
import cn.com.ddapp.ddm.widget.ImageViewUpLoad;

/**
 * Created by caopenghui on 2016-08-06.
 */
public class OrderEvalActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.listview)
    ListView listview;

    @BindView(R.id.error_layout)
    EmptyLayout mEmptyLayout;

    @BindView(R.id.commit)
    TextView mCommit;

    public static final int ACTION_TYPE_ALBUM = 0;//相册
    public static final int ACTION_TYPE_PHOTO = 1;//拍照

    private String theLarge, theThumbnail;
    private File imgFile;

    private List<GoodsEval> goodsEvalList = new ArrayList<>();


    private HashMap<Integer,List<Bitmap>> bitmapsMap = new HashMap<>();//存储bitmap
    private HashMap<Integer,List<File>> fileMap = new HashMap<>();//存储文件
    private int index;//当前操作第几张图
    private int currentPosition;
    private  ViewHolder currentHolder;

    //需要提交的数据
    private String levelIds="";
    private String contents="";


    private Handler   handler = new Handler(){
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 1 && msg.obj != null) {
                Bitmap bitmap = (Bitmap)msg.obj;
                List<Bitmap> bitmapList = bitmapsMap.get(currentPosition);
                List<File> fileList = fileMap.get(currentPosition);
                if(index== ImageViewUpLoad.PIC_ONE){//增加第一张
                    if(bitmapList.size()>=1){
                        bitmapList.remove(0);
                        fileList.remove(0);
                    }
                    bitmapList.add(0,bitmap);
                    fileList.add(0,imgFile);
                    currentHolder.iv_img1.setImageBitmap(bitmap);
                    currentHolder.iv_add_img1.setVisibility(View.GONE);
                }else if(index==ImageViewUpLoad.PIC_TWO){//增加第二张
                    if(bitmapList.size()==0){
                        bitmapList.add(bitmap);
                        fileList.add(imgFile);
                        currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.VISIBLE);
                        currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
                    } else if(bitmapList.size()==1){
                        bitmapList.add(bitmap);
                        fileList.add(imgFile);
                        currentHolder.iv_img2.setImageBitmap(bitmapList.get(1));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.GONE);
                        currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
                    }else if(bitmapList.size()==2){
                        bitmapList.remove(1);
                        bitmapList.add(1,bitmap);
                        fileList.remove(1);
                        fileList.add(1,imgFile);
                        currentHolder.iv_img2.setImageBitmap(bitmapList.get(1));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.GONE);
                        currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
                    }else if(bitmapList.size()==3){
                        bitmapList.remove(1);
                        bitmapList.add(1,bitmap);
                        fileList.remove(1);
                        fileList.add(1,imgFile);
                        currentHolder.iv_img1.setImageBitmap(bitmapList.get(1));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.GONE);
                        currentHolder.iv_add_img3.setVisibility(View.GONE);
                    }
                }else if(index==ImageViewUpLoad.PIC_THREE){//增加第三张
                    if(bitmapList.size()==0){
                        bitmapList.add(bitmap);
                        fileList.add(imgFile);
                        currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.VISIBLE);
                        currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
                    } else if(bitmapList.size()==1){
                        bitmapList.add(bitmap);
                        fileList.add(imgFile);
                        currentHolder.iv_img2.setImageBitmap(bitmapList.get(1));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.GONE);
                        currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
                    }else if(bitmapList.size()==2){
                        bitmapList.add(bitmap);
                        fileList.add(imgFile);
                        currentHolder.iv_img3.setImageBitmap(bitmapList.get(2));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.GONE);
                        currentHolder.iv_add_img3.setVisibility(View.GONE);
                    }else if(bitmapList.size()==3){
                        bitmapList.remove(2);
                        bitmapList.add(2,bitmap);
                        fileList.remove(2);
                        fileList.add(2,imgFile);
                        currentHolder.iv_img3.setImageBitmap(bitmapList.get(2));
                        currentHolder.iv_add_img1.setVisibility(View.GONE);
                        currentHolder.iv_add_img2.setVisibility(View.GONE);
                        currentHolder.iv_add_img3.setVisibility(View.GONE);
                    }
                }
                bitmapsMap.put(currentPosition,bitmapList);
                fileMap.put(currentPosition,fileList);
            }
        }
    };

    private String getActivityTag(){
        return OrderEvalActivity.class.getSimpleName();
    }
    @Override
    public void initView() {
        title.setText(BaseApplication.getIntstance().getResources().getString(R.string.goods_eval));
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(this);
        listview.setAdapter(adapter);
        mCommit.setOnClickListener(this);
    }

    @Override
    public void initData() {
        requestData();
    }

    private void requestData() {
        mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
        String userId =  SPUtils.getStringData(this, SPUtils.USERID);
        final OkUtilCallback okUtilCallback =  new OkUtilCallback(mEmptyLayout) {
            @Override
            public void onMyResponse(String response, int id) {
                TLog.log(getActivityTag(),response);
                GoodsEvalEntity entity = gson.fromJson(response,GoodsEvalEntity.class);
                if((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))&&entity.getLogin()){
                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                }else if((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))){
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT,0, Gravity.CENTER);
                }else{
                    goodsEvalList = entity.getList();
                    adapter.notifyDataSetChanged();
                    for(int i=0;i<goodsEvalList.size();i++){
                        bitmapsMap.put(i,new ArrayList<Bitmap>());
                        fileMap.put(i,new ArrayList<File>());
                    }
                }
            }
        };
        OKUtilAPI.post(OKUtilAPI.evalList, "userId=" + userId+"&id="+getIntent().getIntExtra("orderId",0), okUtilCallback);
    }


    private void handleSelectPicture( int index) {
        final CommonDialog dialog = DialogHelper
                .getPinterestDialogCancelable(this);
        dialog.setTitle(R.string.choose_picture);
        dialog.setNegativeButton(R.string.cancel, null);
        dialog.setItemsWithoutChk(
                BaseApplication.getIntstance().getResources().getStringArray(R.array.choose_picture),
                new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        dialog.dismiss();
                        goToSelectPicture(position);
                    }
                });
        dialog.show();
    }

    private void goToSelectPicture(int position) {
        theLarge = "";
        theThumbnail = "";
        switch (position) {
            case ACTION_TYPE_ALBUM:
                Intent intent;
                if (Build.VERSION.SDK_INT < 19) {
                    intent = new Intent();
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, BaseApplication.getIntstance().getResources().getString(R.string.choose_picture)),
                            ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD);
                } else {
                    intent = new Intent(Intent.ACTION_PICK,
                            MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, BaseApplication.getIntstance().getResources().getString(R.string.choose_picture)),
                            ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD);
                }
                break;
            case ACTION_TYPE_PHOTO:
                // 判断是否挂载了SD卡
                String savePath = "";
                String storageState = Environment.getExternalStorageState();
                if (storageState.equals(Environment.MEDIA_MOUNTED)) {
                    savePath = Environment.getExternalStorageDirectory()
                            .getAbsolutePath() + "/somosteld/Camera/";
                    File savedir = new File(savePath);
                    if (!savedir.exists()) {
                        savedir.mkdirs();
                    }
                }

                // 没有挂载SD卡，无法保存文件
                if (StringUtils.isEmpty(savePath)) {
                    BaseApplication.showToastShort("无法保存照片，请检查SD卡是否挂载");
                    return;
                }

                String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
                        .format(new Date());
                String fileName = "ddapp_" + timeStamp + ".jpg";// 照片命名
                File out = new File(savePath, fileName);
                Uri uri = Uri.fromFile(out);

                theLarge = savePath + fileName;// 该照片的绝对路径

                intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                startActivityForResult(intent,
                        ImageUtils.REQUEST_CODE_GETIMAGE_BYCAMERA);
                break;
            default:
                break;
        }
    }

    @Override
    public void onActivityResult(final int requestCode, final int resultCode,
                                 final Intent imageReturnIntent) {
        if (resultCode != Activity.RESULT_OK)
            return;
        new Thread() {
            private String selectedImagePath;

            @Override
            public void run() {
                Bitmap bitmap = null;

                if (requestCode == ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD) {
                    if (imageReturnIntent == null)
                        return;
                    Uri selectedImageUri = imageReturnIntent.getData();
                    if (selectedImageUri != null) {
                        selectedImagePath = ImageUtils.getImagePath(
                                selectedImageUri, OrderEvalActivity.this);
                    }

                    if (selectedImagePath != null) {
                        theLarge = selectedImagePath;
                    } else {
                        bitmap = ImageUtils.loadPicasaImageFromGalley(
                                selectedImageUri, OrderEvalActivity.this);
                    }

                    if (MethodsCompat
                            .isMethodsCompat(Build.VERSION_CODES.ECLAIR_MR1)) {
                        String imaName = FileUtil.getFileName(theLarge);
                        if (imaName != null)
                            bitmap = ImageUtils.loadImgThumbnail(OrderEvalActivity.this,
                                    imaName,
                                    MediaStore.Images.Thumbnails.MICRO_KIND);
                    }
                    if (bitmap == null && !StringUtils.isEmpty(theLarge))
                        bitmap = ImageUtils
                                .loadImgThumbnail(theLarge, 100, 100);
                } else if (requestCode == ImageUtils.REQUEST_CODE_GETIMAGE_BYCAMERA) {
                    // 拍摄图片
                    if (bitmap == null && !StringUtils.isEmpty(theLarge)) {
                        bitmap = ImageUtils
                                .loadImgThumbnail(theLarge, 100, 100);
                    }
                }

                if (bitmap != null) {// 存放照片的文件夹
                    String savePath = Environment.getExternalStorageDirectory()
                            .getAbsolutePath() + "/SOMOSTELD/Camera/";
                    File savedir = new File(savePath);
                    if (!savedir.exists()) {
                        savedir.mkdirs();
                    }

                    String largeFileName = FileUtil.getFileName(theLarge);
                    String largeFilePath = savePath + largeFileName;
                    // 判断是否已存在缩略图
                    if (largeFileName.startsWith("thumb_")
                            && new File(largeFilePath).exists()) {
                        theThumbnail = largeFilePath;
                        imgFile = new File(theThumbnail);
                    } else {
                        // 生成上传的800宽度图片
                        String thumbFileName = "thumb_" + largeFileName;
                        theThumbnail = savePath + thumbFileName;
                        if (new File(theThumbnail).exists()) {
                            imgFile = new File(theThumbnail);
                        } else {
                            try {
                                // 压缩上传的图片
                                ImageUtils.createImageThumbnail(OrderEvalActivity.this,
                                        theLarge, theThumbnail, 800, 80);
                                imgFile = new File(theThumbnail);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    Message msg = new Message();
                    msg.what = 1;
                    msg.obj = bitmap;
                    handler.sendMessage(msg);
                }
            };
        }.start();
    }

    final BaseAdapter adapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return goodsEvalList.size();
        }

        @Override
        public Object getItem(int i) {
            return goodsEvalList.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup viewGroup) {

            convertView= LayoutInflater.from(OrderEvalActivity.this).inflate(R.layout.order_eval_item,null);
            final ViewHolder holder = new ViewHolder(convertView);

           GoodsEval goodsEval =  goodsEvalList.get(position);

            Glide.with(OrderEvalActivity.this).load(OKUtilAPI.imgBaseUrl+goodsEval.getGoodsImg()).into(holder.goodsLogo);
            holder.goodsName.setText(goodsEval.getGoodsName());
            holder.goodsPrice.setText(AppConfig.MONEY_SYMBEL+new DecimalFormat("######0.00").format(goodsEval.getPrice()));

            holder.iv_clear_img1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_ONE;
                    handleDelPicture(ImageViewUpLoad.PIC_ONE);
                }
            });
            holder.iv_clear_img2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_TWO;
                    handleDelPicture(ImageViewUpLoad.PIC_TWO);
                }
            });
            holder.iv_clear_img3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    index=ImageViewUpLoad.PIC_THREE;
                    handleDelPicture(ImageViewUpLoad.PIC_THREE);
                }
            });
            holder.iv_img1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_ONE;
                    handleSelectPicture(ImageViewUpLoad.PIC_ONE);
                }
            });
            holder.iv_add_img1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_ONE;
                    handleSelectPicture(ImageViewUpLoad.PIC_ONE);
                }
            });
            holder.iv_img2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_ONE;
                    handleSelectPicture(ImageViewUpLoad.PIC_ONE);
                }
            });
            holder.iv_add_img2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_TWO;
                    handleSelectPicture(ImageViewUpLoad.PIC_TWO);
                }
            });
            holder.iv_img3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_ONE;
                    handleSelectPicture(ImageViewUpLoad.PIC_ONE);
                }
            });
            holder.iv_add_img3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    currentPosition = position;
                    currentHolder = holder;
                    index=ImageViewUpLoad.PIC_THREE;
                    handleSelectPicture(ImageViewUpLoad.PIC_THREE);
                }
            });


            return convertView;
        }


    };

    /**
     * 删除照片
     * @param index
     */
    private void handleDelPicture(int index) {
        List<Bitmap> bitmapList = bitmapsMap.get(currentPosition);
        List<File>  fileList = fileMap.get(currentPosition);
        if(index==ImageViewUpLoad.PIC_ONE){//删除第一张
            if(bitmapList.size()==1){
                bitmapList.remove(0);
                fileList.remove(0);
                currentHolder.iv_add_img1.setVisibility(View.VISIBLE);
                currentHolder.iv_add_img2.setVisibility(View.VISIBLE);
                currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
            }else if(bitmapList.size()==2){
                bitmapList.remove(0);
                fileList.remove(0);
                currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
                currentHolder.iv_add_img1.setVisibility(View.GONE);
                currentHolder.iv_add_img2.setVisibility(View.VISIBLE);
                currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
            }else if(bitmapList.size()==3){
                bitmapList.remove(0);
                fileList.remove(0);
                currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
                currentHolder.iv_img2.setImageBitmap(bitmapList.get(1));
                currentHolder.iv_add_img1.setVisibility(View.GONE);
                currentHolder.iv_add_img2.setVisibility(View.GONE);
                currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
            }
        }else if(index==ImageViewUpLoad.PIC_TWO){//删除第二张
            if(bitmapList.size()==2){
                bitmapList.remove(1);
                fileList.remove(1);
                currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
                currentHolder.iv_add_img1.setVisibility(View.GONE);
                currentHolder.iv_add_img2.setVisibility(View.VISIBLE);
                currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
            }else if(bitmapList.size()==3){
                bitmapList.remove(1);
                fileList.remove(0);
                currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
                currentHolder.iv_img2.setImageBitmap(bitmapList.get(1));
                currentHolder.iv_add_img1.setVisibility(View.GONE);
                currentHolder.iv_add_img2.setVisibility(View.GONE);
                currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
            }
        }else if(index==ImageViewUpLoad.PIC_TWO){//删除第三张
                bitmapList.remove(2);
                fileList.remove(0);
                currentHolder.iv_img1.setImageBitmap(bitmapList.get(0));
               currentHolder.iv_img2.setImageBitmap(bitmapList.get(1));
                currentHolder.iv_add_img1.setVisibility(View.GONE);
                currentHolder.iv_add_img2.setVisibility(View.GONE);
                currentHolder.iv_add_img3.setVisibility(View.VISIBLE);
        }
        bitmapsMap.put(currentPosition,bitmapList);
    }

    class ViewHolder {
        public ViewHolder(View view){
            goodsLogo = (ImageView)view.findViewById(R.id.goodsLogo);
            goodsName = (TextView)view.findViewById(R.id.goodsName);
            goodsPrice = (TextView)view.findViewById(R.id.goodsPrice);
            imageViewLoader = (ImageViewUpLoad)view.findViewById(R.id.imageViewLoader);

            iv_img1 = (ImageView)imageViewLoader.findViewById(R.id.iv_img1);
            iv_img2 = (ImageView)imageViewLoader.findViewById(R.id.iv_img2);
            iv_img3 = (ImageView)imageViewLoader.findViewById(R.id.iv_img3);

            iv_clear_img1 = (ImageView)imageViewLoader.findViewById(R.id.iv_clear_img1);
            iv_clear_img2 = (ImageView)imageViewLoader.findViewById(R.id.iv_clear_img2);
            iv_clear_img3 = (ImageView)imageViewLoader.findViewById(R.id.iv_clear_img3);

            iv_add_img1 = (ImageView)imageViewLoader.findViewById(R.id.iv_add_img1);
            iv_add_img2 = (ImageView)imageViewLoader.findViewById(R.id.iv_add_img2);
            iv_add_img3 = (ImageView)imageViewLoader.findViewById(R.id.iv_add_img3);

        }
        public ImageView goodsLogo;
        public TextView goodsName;
        public TextView goodsPrice;
        public ImageViewUpLoad imageViewLoader;
        public ImageView iv_img1,iv_img2,iv_img3;
        public ImageView iv_clear_img1,iv_clear_img2,iv_clear_img3;
        public ImageView iv_add_img1,iv_add_img2,iv_add_img3;
        public RatingBar ratingBar;

    }

    @Override
    public int getContentViewId() {
        return R.layout.order_eval_activity;
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }

    @Override
    public void onClick(View view) {
        if(view.getId()==back.getId()){
            ActivityManager.getInstance().finishActivity();
        }else if(view.getId()==mCommit.getId()){
            commitOrderEvalRequest();
        }
    }

    /**
     * 提交订单评价请求
     */
    private void commitOrderEvalRequest() {



        if(goodsEvalList.size()<=0){
            return;
        }
        for(int i=0;i<listview.getChildCount();i++){
            TLog.log("listview.getChildCount()"+listview.getChildCount());
            LinearLayout childLinearlayout = (LinearLayout)listview.getChildAt(i);
            RatingBar ratingBar = (RatingBar)childLinearlayout.findViewById(R.id.room_ratingbar);
            EditText contentEditText = (EditText)childLinearlayout.findViewById(R.id.edittextContent);
            if(StringUtils.isEmpty(contentEditText.getText().toString())){
                BaseApplication.showToast(BaseApplication.getIntstance().getResources().getString(R.string.content_none));
                return;
            }
            levelIds +=Math.round( ratingBar.getRating()) +",";
            contents += contentEditText.getText().toString()+AppConfig.SPLIT;
        }

        levelIds=levelIds.substring(0,levelIds.lastIndexOf(","));
        contents=contents.substring(0,contents.lastIndexOf(AppConfig.SPLIT));
        String goodsId = "";
        for(GoodsEval eval : goodsEvalList){
            goodsId += eval.getGoodsId()+",";
        }
        goodsId=goodsId.substring(0,goodsId.length()-1);

        showWaitDialog(R.string.goods_eval_ing);

        String userId =  SPUtils.getStringData(this, SPUtils.USERID);
        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                hideWaitDialog();
                TLog.log(getActivityTag(), response);
                Entity entity = gson.fromJson(response, Entity.class);
                if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult())) && entity.getLogin()) {
                    mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                    BaseApplication.getIntstance().showToast(entity.getResult(), Toast.LENGTH_SHORT, 0, Gravity.CENTER);
                } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(entity.getResult()))) {
                        ActivityManager.getInstance().finishActivity(OrderEvalActivity.this);
                }
            }
        };

        HashMap<String,List<File>> files = new HashMap<>();
        for(Integer position : fileMap.keySet()){
            files.put(AppConfig.IMGS+goodsEvalList.get(position).getGoodsId()+"",fileMap.get(position));
        }

        OKUtilAPI.file(OKUtilAPI.eval, "userId=" + userId + "&id=" + getIntent().getIntExtra("orderId",0)+"&goodsIds="+goodsId+"&levelIds="+levelIds+"&contents="+contents, okUtilCallback,files);

    }


}
